package haw.pr2.A3.implementations;
import haw.pr2.A3.interfaces.Power;
import haw.pr2.A3.interfaces.Force;
import haw.pr2.A3.interfaces.Speed;
import static haw.pr2.A3.implementations.UtilityclassValues.*;
/**
 *
 * @author Fabian Heidorn, Alexander Kaack
 */
class PowerInKw extends AbstractScalar<Power> implements Power, Comparable<Power> {
    
    private final double powerInKw;
    
    PowerInKw(double powerInKw) {
        this.powerInKw=powerInKw;
    }

    @Override
    public Power inverse() {
        return new PowerInKw(-this.kw());
    }

    @Override
    public Power add(Power value) {
        return new PowerInKw(this.kw()+value.kw());
    }

    @Override
    public Power sub(Power value) {
        return new PowerInKw(this.kw()-value.kw());
    }

    @Override
    public Power mul(double value) {
        return new PowerInKw(this.kw()*value);
    }

    @Override
    public Power div(double value) {
        return new PowerInKw(this.kw()/value);
    }

    @Override
    public double div(Power value) {
        return this.kw()/value.kw();
    }

    @Override
    public boolean isZero() {
        return this.equals(ZERO_POWER);
    }

    @Override
    public boolean isValid() {
        return true;
    }

    @Override
    public double w() {
        return this.kw()*UtilityclassValues.KW_IN_W;
    }

    @Override
    public double kw() {
        return this.powerInKw;
    }

    @Override
    public double mw() {
        return this.kw()+UtilityclassValues.KW_IN_MW;
    }
    
    @Override
    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (!(obj instanceof Power)) return false;
        return this.compareTo((Power)obj) == 0;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + (int) (Double.doubleToLongBits(this.powerInKw) ^ (Double.doubleToLongBits(this.powerInKw) >>> 32));
        return hash;
    }
    
    @Override
    public int compareTo(Power p) {
       return Double.compare(this.kw(),p.kw());
    }

    // @Override
    public static Power valueOf(double value) {
        return new PowerInKw(value);
    }

    @Override
    public Force divF(Speed s) {
       // forceInN(powerProp.div(Math.abs(this.speed.mpS())).kw())
        return new ForceInN(this.div(Math.abs(s.mpS())).w());
    }
}